package LeetCode.month04.day101;

import java.util.Arrays;

/**
 * @author 16778
 * @date 2025/11/11 8:09
 * @description
 */
public class No474 {
    static void main() {
        findMaxForm(new String[]{"10","0001", "111001", "1", "0"},5,3);
    }
    public static int findMaxForm(String[] strs, int m, int n) {
        int len = strs.length;
        int[][][] dp = new int[len+1][m+1][n+1];
        for (int i = 0; i < len; i++) {
            int cnt0 =(int) strs[i].chars().filter(c->c=='0').count();
            int cnt1 = strs[i].length()-cnt0;
            for (int j = 0; j <= m; j++) {
                for (int k = 0; k <= n; k++) {
                    if(j>=cnt0&&k>=cnt1){
                        dp[i+1][j][k]=Math.max(dp[i][j][k],dp[i][j-cnt0][k-cnt1]+1);
                    }else{
                        dp[i+1][j][k]=dp[i][j][k];
                    }
                }
            }
        }
        for (int[][] ints : dp) {
            for (int[] anInt : ints) {
                System.out.println(Arrays.toString(anInt));
            }
            System.out.println("----------------------------------");
        }
        return dp[len][m][n];
    }
}
